Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
hmpo-model
Advanced tools
change
event notifications if options.silent
is setNormally this would be used as an abstract class and extended with your own implementation.
Implementations would normally define at least a url
method to define the target of API calls.
There are three methods for API interaction corresponding to GET, POST, and DELETE http methods:
fetch
var model = new Model();
model.fetch(function (err, data, responseTime) {
console.log(data);
});
save
var model = new Model();
model.set({
property: 'properties are sent as JSON request body by default'
});
model.save(function (err, data, responseTime) {
console.log(data);
});
The method can also be overwritten by passing options
var model = new Model();
model.set({
property: 'this will be sent as a PUT request'
});
model.save({ method: 'PUT' }, function (err, data, responseTime) {
console.log(data);
});
delete
var model = new Model();
model.delete(function (err, data) {
console.log(data);
});
If no url
method is defined then the model will use the options parameter and Node's url.format method to construct a URL.
var model = new Model();
// make a GET request to http://example.com:3000/foo/bar
model.fetch({
protocol: 'http',
hostname: 'example.com',
port: 3000,
path: '/foo/bar'
}, function (err, data, responseTime) {
console.log(data);
});
API requests will emit events as part of their lifecycle.
sync
is emitted when an API request is sent
model.on('sync', function (settings) { });
success
is emitted when an API request successfully completes
model.on('success', function (data, settings, statusCode, responseTime) { });
fail
is emitted when an API request fails
model.on('fail', function (err, data, settings, statusCode, responseTime) { });
API requests will fire hooks specified in model options as part of their lifecycle.
new Model(null, options);
sync
hook is fired when an API request is sent
options.hooks.sync({ settings });
success
hook is fired when an API request successfully completes
options.hooks.success({ data, settings, statusCode, responseTime });
fail
hook is fired when an API request fails
options.hooks.fail({ err, data, settings, statusCode, responseTime });
FAQs
Simple model for interacting with http/rest apis.
We found that hmpo-model demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.